package fuxi;

import java.io.*;

public class demo5 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 序列化复习
        //把Student类对象写入本地文件当( Student.txt)中

        Student s = new Student("张三", 18, "北京");
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("student.txt"));
        oos.writeObject(s);

        oos.close();

        System.out.println("序列化成功");
        //反序列化 ObjectInputStream反序列化流，将之前使用ObjectOutputStream序列化的原始数据恢复为对象。
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("student.txt"));
        Student  o = (Student)ois.readObject();
        //打印本地文件里的数据
        System.out.println(o);
    }
}
